package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.entity.NursingProject;
import com.zzyl.entity.Room;
import com.zzyl.entity.RoomType;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.utils.ObjectUtil;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import com.zzyl.vo.RoomTypeVo;
import com.zzyl.vo.RoomVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public List<NursingLevelVo> findAll() {
        List<NursingLevel> nursingLevels = nursingLevelMapper.selectAll();
        return nursingLevels.stream().map(nursingLevel -> {
            NursingLevelVo nursingLevelVo = new NursingLevelVo();
            // 将房间实体对象拷贝到房间视图对象
            BeanUtils.copyProperties(nursingLevel, nursingLevelVo);

            return nursingLevelVo;
        }).collect(Collectors.toList());

//        List<RoomType> roomTypes = roomTypeMapper.findRoomTypeList();
//        return convertToVOList(roomTypes);
    }

    @Override
    public void add(NursingLevelDto dto) {
//        Room room = new Room();
//        BeanUtils.copyProperties(roomDto, room);

        NursingLevel nursingLevel = new NursingLevel();
        nursingLevel.setUpdateTime(LocalDateTime.now());
        BeanUtils.copyProperties(dto, nursingLevel);
        nursingLevelMapper.addAll(dto);
    }

    @Override
    public PageResponse<NursingLevelVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevel> nursingLevels = nursingLevelMapper.selectByPage(name, status);
        return PageResponse.of(nursingLevels, NursingLevelVo.class);

    }

    @Override
    public NursingLevelVo getById(Long id) {
        NursingLevel nursingLevel = nursingLevelMapper.selectById(id);
        NursingLevelVo nursingLevelVo = BeanUtil.toBean(nursingLevel, NursingLevelVo.class);
        return nursingLevelVo;

    }

    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDto,nursingLevel);
        nursingLevelMapper.update(nursingLevel);
//        NursingProject nursingProject = new NursingProject();
//        BeanUtils.copyProperties(nursingProjectDto, nursingProject);
//        nursingProjectMapper.update(nursingProject);
    }

    @Override
    public void deleteById(Long id) {
        nursingLevelMapper.deleteById(id);
    }

    @Override
    public void statueById(Long id, Integer status) {
        nursingLevelMapper.statueById(id, status);
    }
}

